package com.travel.server.manager.impl.command.project;

import com.travel.common.exception.WorkCode;
import com.travel.common.exception.WorkException;
import com.travel.server.manager.dto.request.project.QueryProjectOtherInfoRequest;
import com.travel.server.manager.dto.response.project.QueryProjectOtherInfoResponse;
import com.travel.server.manager.impl.command.AbstractCommand;
import com.travel.server.manager.impl.dal.ProjectDal;
import com.travel.server.manager.model.ProjectInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: LiZhenhui
 * @Date: 2018/11/1 10:13
 * @Desc:
 */
@Component
@Slf4j
public class QueryProjectOtherInfoCommand extends AbstractCommand<QueryProjectOtherInfoRequest,QueryProjectOtherInfoResponse> {

    @Autowired
    private ProjectDal projectDal;

    @Override
    protected void checkInput(QueryProjectOtherInfoRequest request) {
        if(request.getId() == null){
            throwInvalidParam();
        }
    }

    @Override
    public QueryProjectOtherInfoResponse handle(QueryProjectOtherInfoRequest request) {
        checkInput(request);

        int id = request.getId();
        ProjectInfo projectInfo = projectDal.selectById(id);
        if(projectInfo == null){
            throw new WorkException(WorkCode.RECORD_NOT_EXIST);
        }

        QueryProjectOtherInfoResponse response = new QueryProjectOtherInfoResponse();
        response.setAttention(projectInfo.getAttention());
        response.setExplains(projectInfo.getCostExplains());

        return response;
    }
}
